//Alex Silkin
#include "InspectorTest.h"
#include "InspectorAgent.h"
#include <iostream>
#include "gmock/gmock.h"
#include "gtest/gtest.h"

#include "Enums.h"
#include "Kit.h"
#include "Part.h"

class InspectorAgent;

//init test
InspectorTest::InspectorTest() : inspector("Inspector Test") {

}

 void InspectorTest::SetUp() {
	 this->inspector.SetGui(&gui);

	 this->inspector.SetKitRobot(&kitRobot);

	 table = new Table();
	 this->inspector.SetTable(table);

 }

 bool InspectorTest::runScheduler() {
	return inspector.pickAndExecuteAnAction();
}

bool InspectorTest::isAllReferencesInitialized() {
	if(inspector.GetKitRobot() == NULL || inspector.GetGui() == NULL || inspector.GetTable() == NULL)
		return false;
	return true;
}

TEST_F(InspectorTest, InitializationTest){
	EXPECT_TRUE(isAllReferencesInitialized());
}


TEST_F(InspectorTest, InitialSchedulerTest){
	EXPECT_FALSE(runScheduler());
}

TEST_F(InspectorTest, InspectGoodKitOnTableTest){
	EXPECT_FALSE(runScheduler());

	Kit* kit = new Kit();

	std::vector<PartType> partTypesNeeded;
	partTypesNeeded.push_back(A);
	kit->partTypesNeeded = partTypesNeeded;

	Part* part = new Part(A);
	kit->addPart(part);

	this->table->remove(2);
	this->table->insert(kit, 2);

	inspector.msgInspectKit();

	EXPECT_CALL(this->gui, takePicture());
	EXPECT_CALL(this->kitRobot, msgHereIsKitState(Good));

	EXPECT_TRUE(runScheduler());
	EXPECT_FALSE(runScheduler());
}

TEST_F(InspectorTest, InspectBadKitOnTableTest){
	EXPECT_FALSE(runScheduler());

	Kit* kit = new Kit();

	std::vector<PartType> partTypesNeeded;
	partTypesNeeded.push_back(A);
	kit->partTypesNeeded = partTypesNeeded;

	Part* part = new Part(B);
	kit->addPart(part);

	this->table->remove(2);
	this->table->insert(kit, 2);

	inspector.msgInspectKit();

	EXPECT_CALL(this->gui, takePicture());
	EXPECT_CALL(this->kitRobot, msgHereIsKitState(Bad));

	EXPECT_TRUE(runScheduler());
	EXPECT_FALSE(runScheduler());
}